package system

import (
	"github.com/goravel/framework/contracts/http"
	httpfacade "github.com/hulutech-web/http_result"
	"goravel/app/models/systemEntity"
)

type ButtonPermissionController struct {
	// Dependent services
}

func NewButtonPermissionController() *ButtonPermissionController {
	return &ButtonPermissionController{
		// Inject services
	}
}

// Index 分页查询，支持搜索，路由参数?name=xxx&pageSize=1&currentPage=1&sort=xxx&order=xxx,等其他任意的查询参数
// @Summary      分页查询
// @Description  分页查询
// @Tags         ButtonPermissionController
// @Accept       json
// @Produce      json
// @Id ButtonPermissionIndex
// @Security ApiKeyAuth
// @Param Authorization header string false "Bearer 用户令牌"
// @Param  name  query  string  false  "name"
// @Param  pageSize  query  string  false  "pageSize"
// @Param  currentPage  query  string  false  "currentPage"
// @Param  sort  query  string  false  "sort"
// @Param  order  query  string  false  "order"
// @Success 200 {string} json {}
// @Router       /api/btn_permission [get]
func (r *ButtonPermissionController) Index(ctx http.Context) http.Response {
	ButtonPermissions := []systemEntity.ButtonPermission{}
	queries := ctx.Request().Queries()
	res, err := httpfacade.NewResult(ctx).SearchByParams(queries, nil).ResultPagination(&ButtonPermissions)
	if err != nil {
		return httpfacade.NewResult(ctx).Error(http.StatusInternalServerError, "", err.Error())
	}
	return res
}

// List 列表查询
// @Summary      列表查询
// @Description  列表查询
// @Tags         ButtonPermissionController
// @Accept       json
// @Produce      json
// @Id ButtonPermissionList
// @Security ApiKeyAuth
// @Param Authorization header string false "Bearer 用户令牌"
// @Success 200 {string} json {}
// @Router       /api/btn_permission/list [get]
func (r *ButtonPermissionController) List(ctx http.Context) http.Response {
	permissions := []systemEntity.ButtonPermission{}
	queries := ctx.Request().Queries()
	httpfacade.NewResult(ctx).SearchByParams(queries, map[string]interface{}{}).List(&permissions)
	return httpfacade.NewResult(ctx).Success("", permissions)
}
